package com.cn.ant.modules.wechat.service;

import com.cn.ant.common.persistence.Page;
import com.cn.ant.common.service.BaseService;
import com.cn.ant.common.utils.Identities;
import com.cn.ant.modules.wechat.dao.ReceiveTextMapper;
import com.cn.ant.modules.wechat.entity.ReceiveText;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

/**
 * Created by AntDream on 2015/3/22.
 */
@Service
@Transactional(readOnly = true)
public class ReceiveTextService extends BaseService {
    @Autowired
    private ReceiveTextMapper receiveTextMapper;

    public ReceiveText get(String id) {
        return receiveTextMapper.get(id);
    }

    @Transactional(readOnly = false)
    public void save(ReceiveText receiveText) {
        receiveText.setId(Identities.generateUUID());
        receiveTextMapper.insert(receiveText);
    }

    @Transactional(readOnly = false)
    public void update(ReceiveText receiveText) {
        receiveTextMapper.update(receiveText);
    }

    @Transactional(readOnly = false)
    public void delete(String id) {
        receiveTextMapper.delete(id);
    }

    public Page<ReceiveText> query(Page<ReceiveText> page, Map<String, Object> params) {
        params.put("startIdx", page.getFirstResult());
        params.put("pageSize", page.getPageSize());
        page.setList(receiveTextMapper.query(params));
        page.setCount(receiveTextMapper.queryCount(params));
        return page;
    }
}
